<?php
/**
 * Created by : Sandi Rizky Kharisma (sandi.informatics08@gmail.com)
 * This Class Generated for CRUD purpose only
 */
class m_mohon_kredit extends CI_Model {

    function __construct() {
        parent::__construct();
    }

    public function get($where = null, $limit = null, $offset = null) {
        if($where != null) $this->db->where($where);
        if($limit != null && $offset != null) $this->db->limit($limit, $offset);
        return $this->db->get("mohon_kredit");
    }

    function get_all($limit, $uri) {

        $result = $this->db->get('mohon_kredit', $limit, $uri);
        if ($result->num_rows() > 0) {
            return $result->result_array();
        } else {
            return array();
        }
    }

    function get_one($id) {
        $this->db->select('mohon_kredit.*');
        $this->db->select('info_usaha.BUNGA_PER_BULAN');
        $this->db->select('anggota.NAMA_ANGGOTA');
        $this->db->select('anggota.ALAMAT');
        $this->db->select('anggota.NAMA_DIVISI');
        $this->db->join('info_usaha', 'info_usaha.KODE_USAHA = mohon_kredit.KODE_USAHA');
        $this->db->join('anggota', 'anggota.ID_ANGGOTA = mohon_kredit.ID_ANGGOTA');

        $this->db->where('ID_MOHON_KREDIT', $id);
        $result = $this->db->get('mohon_kredit');
        if ($result->num_rows() == 1) {
            return $result;
        } else {
            return array();
        }
    }

    function insert() {
        $data = array(

                'ID_ANGGOTA' => $this->input->post('ID_ANGGOTA', TRUE),

                'KODE_USAHA' => $this->input->post('KODE_USAHA', TRUE),

                'UMUR' => $this->input->post('UMUR', TRUE),

                'ALAMAT_KANTOR' => $this->input->post('ALAMAT_KANTOR', TRUE),

                'PIUTANG' => $this->input->post('MAX_PIUTANG', TRUE),

                'CICILAN' => $this->input->post('MAX_CICIL', TRUE),

                'BAYAR_PER_BULAN' => $this->input->post('BAYAR_PER_BULAN', TRUE),

                'TANGGAL_PINJAM' => $this->input->post('TANGGAL_PINJAM', TRUE),

                'TANGGAL_CATAT' => date("Y-m-d"),

        );
        $this->db->insert('mohon_kredit', $data);
        return $this->db->insert_id();
    }

    function update($id) {
        $data = array(

                'ID_ANGGOTA' => $this->input->post('ID_ANGGOTA', TRUE),

                'KODE_USAHA' => $this->input->post('KODE_USAHA', TRUE),

                'UMUR' => $this->input->post('UMUR', TRUE),

                'ALAMAT_KANTOR' => $this->input->post('ALAMAT_KANTOR', TRUE),

                'PIUTANG' => $this->input->post('PIUTANG', TRUE),

                'CICILAN' => $this->input->post('CICILAN', TRUE),

                'TANGGAL_PINJAM' => $this->input->post('TANGGAL_PINJAM', TRUE),

        );
        $this->db->where('ID_MOHON_KREDIT', $id);
        return $this->db->update('mohon_kredit', $data);
    }

    function delete($id) {
        $this->db->where('ID_MOHON_KREDIT', $id);
        return $this->db->delete('mohon_kredit');
    }

}
?>
